package genedit.controller.interfaceActions;

import genedit.model.Workspace;
import genedit.view.graph.GraphDocumentView;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zadužena za ponovno izvršavanje poništene akcije u aktivnom dokumentu.
 * 
 * @author Nikola
 * @version 1.0 5/10/13
 */
public class GRedoA extends AbstractAction {
	private static final long serialVersionUID = 1L;

	protected static GRedoA gRedoA = null;

	protected GRedoA() {
		putValue(NAME, "Redo");
		putValue(SHORT_DESCRIPTION, "Redo");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/redo.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_R);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Y"));
	}

	public static AbstractAction getInstance() {
		if (gRedoA == null)
			gRedoA = new GRedoA();
		return gRedoA;
	}

	/**
	 * Akcija govori invokeru da ponovo izvrši poslednje poništenu akciju u
	 * datom aktivnom dokumentu.
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		GraphDocumentView document = Workspace.getInstance().getActiveDocument();
		if (document != null)
			document.getModel().getInvoker().redo();
	}

}